#include "mainwindow.h"
#include "ui_mainwindow.h"
#include "translationrules.h"
#include "asksavedialog.h"
MainWindow::MainWindow(QWidget *parent) :
    QMainWindow(parent),
    ui(new Ui::MainWindow),
    m_modified(false)
{
    ui->setupUi(this);
    fileNew();
    connect(ui->listWidget,SIGNAL(currentTextChanged(QString)),this,SLOT(showRulesSet(QString)));
}

MainWindow::~MainWindow()
{
    delete ui;
}

void MainWindow::fileNew(){
    if(m_modified){
        AskSaveDialog dlg;
        if(dlg.exec()==QDialog::Accepted){
            fileSave();
        }
        m_modified = false;
    }
    cleanUp();
    TranslationRules * defaultRules =  new TranslationRules(tr("Default"),this);
    ui->listWidget->addItem(tr("Default"));
    m_rules[tr("Default")] = defaultRules;
    showRulesSet(tr("Default"));
}

void MainWindow::fileOpen(){

}

void MainWindow::fileSave(){

}

void MainWindow::fileSaveAs(){

}

void MainWindow::quit(){

}

void MainWindow::rulesSetNew(){

}

void MainWindow::rulesSetRemove(){

}

void MainWindow::about(){

}

void MainWindow::help(){

}

void MainWindow::onModified(){

}

void MainWindow::cleanUp(){

}

void MainWindow::showRulesSet(const QString& rulesSetName){
    ui->widget->setTranslationRules(m_rules[rulesSetName]);
}

void MainWindow::changeEvent(QEvent *e)
{
    QMainWindow::changeEvent(e);
    switch (e->type()) {
    case QEvent::LanguageChange:
        ui->retranslateUi(this);
        break;
    default:
        break;
    }
}
